package leetcode.code0263;

public class Solution {
	public boolean isUgly(int n) {
		if (n < 1) {
			return false;
		}
		n = this.n(n, 2);
		n = this.n(n, 3);
		n = this.n(n, 5);
		return n == 1;
	}

	private int n(int n, int mod) {
		while (n % mod == 0) {
			n = n / mod;
		}
		return n;
	}

	private int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}
